import { request } from "@/utils/http";
import React from "react";
import type {
  ResHospitalType,
  HospitalListItem,
  ProvinceList,
  ReqHospitalPageType,
  SearchParams,
  HospitalDetail,
  DepartmentsList,
  ReqGetScheduleRulesParams,
  ReqScheduleRules,
  ScheduleList,
} from "./model/hospitalListType";

// 获取医院设置分页列表
export const reqGetHospitalListApi = (
  page: number,
  limit: number,
  hosname?: string,
  hoscode?: string
) => {
  return request.get<any, ResHospitalType>(
    `/admin/hosp/hospitalSet/${page}/${limit}`,
    {
      params: {
        hosname,
        hoscode,
      },
    }
  );
};

// 添加医院设置
export const reqAddHospitalSetApi = (hospitalInfo: HospitalListItem) => {
  return request.post<any, null>("/admin/hosp/hospitalSet/save", hospitalInfo);
};

// 修改医院
export const reqUpdateHospitalSetApi = (hospitalInfo: HospitalListItem) => {
  return request.put<any, null>("/admin/hosp/hospitalSet/update", hospitalInfo);
};

// 根据医院id获取一条医院设置
export const reqGetHospitalItemApi = (id: number) => {
  return request.get<any, HospitalListItem>(
    `/admin/hosp/hospitalSet/get/${id}`
  );
};

// 删除单个医院
export const reqDeleteHospitalSetApi = (id: number) => {
  return request.delete(`/admin/hosp/hospitalSet/remove/${id}`);
};

// 批量删除医院
export const reqDeleteHospitalSetCheckedApi = (delIdList: React.Key[]) => {
  return request.delete("/admin/hosp/hospitalSet/batchRemove", {
    data: delIdList,
  });
};

// ============================医院列表

// 获取省级列表
export const reqGetProvinceListApi = (dictCode: string = "province") => {
  return request.get<any, ProvinceList>(
    `/admin/cmn/dict/findByDictCode/${dictCode}`
  );
};

// 获取市/区级列表、获取医院类型（parentId固定值为 10000）
export const reqGetCityListOrDistrictListApi = (parentId: number) => {
  return request.get<any, ProvinceList>(
    `/admin/cmn/dict/findByParentId/${parentId}`
  );
};

// 获取分页医院列表
export function reqGetHospitalPageListApi(
  page: number,
  limit: number,
  data?: SearchParams
) {
  return request.get<any, ReqHospitalPageType>(
    `/admin/hosp/hospital/${page}/${limit}`,
    {
      params: data,
    }
  );
}

// 获取医院详情
export function reqGetHospitalDetailApi(id: string) {
  return request.get<any, HospitalDetail>(`/admin/hosp/hospital/show/${id}`);
}

// ==========================医院排班

// 获取医院科室列表
export function reqGetDepartmentsApi(hoscode: string) {
  return request.get<any, DepartmentsList>(`/admin/hosp/department/${hoscode}`);
}

// 医院排班规则数据（Tag渲染的内容）
export function reqGetScheduleRulesApi({
  page,
  limit,
  hoscode,
  depcode,
}: ReqGetScheduleRulesParams) {
  return request.get<any, ReqScheduleRules>(
    `/admin/hosp/schedule/getScheduleRule/${page}/${limit}/${hoscode}/${depcode}`
  );
}

// 获取医院医生排班列表（table渲染的内容）
export function reqGetScheduleListApi(
  hoscode: string,
  depcode: React.Key,
  workDate: string
) {
  return request.get<any, ScheduleList>(
    `/admin/hosp/schedule/findScheduleList/${hoscode}/${depcode}/${workDate}`
  );
}

// 医院上线下线
export function reqUpdateHospitalStatusApi(id: number, status: number) {
  return request.get<any,null>(`/admin/hosp/hospital/updateStatus/${id}/${status}`);
}
